package com.hbfu.zggdwlzzsx.controller;

import com.hbfu.zggdwlzzsx.entity.Authors;
import com.hbfu.zggdwlzzsx.service.AuthorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/authors")
@Slf4j
@CrossOrigin
public class AuthorController {

    @Autowired
    private AuthorService authorService;

    // 查询所有作者
    @GetMapping
    public List<Authors> getAllAuthors(){
        return authorService.getAllAuthors();
    }

    // 查询作者详细信息
    @GetMapping("/{id}")
    public Authors getAuthorDetail(@PathVariable Integer id){
        return authorService.getAuthorDetail(id);
    }

    // 新增方法：添加作者信息
    @PostMapping
    public boolean addAuthor(@RequestBody Authors author) {
        return authorService.save(author);
    }
}